﻿using System;
using System.Collections;
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;

namespace NpcFramework.Traffic.Editor
{
    [CustomEditor(typeof(TrafficLight))]

    public class TrafficLightEditor : UnityEditor.Editor
    {
        private TrafficLight _trafficLight;
        
        private void OnEnable()
        {
            _trafficLight = target as TrafficLight;
        }

        public override void OnInspectorGUI()
        {
            base.OnInspectorGUI();

            for (int i = 0; i < _trafficLight.waitPointMaps.Count; i++)
            {
                GUILayout.BeginHorizontal();
                GUILayout.Label("索引：" + i,GUILayout.Width(60));
                EditorGUILayout.ObjectField(_trafficLight.waitPointMaps[i].WayPoint, typeof(GameObject),GUILayout.Width(160));
                if (GUILayout.Button("添加等待点"))
                {
                    _trafficLight.AddWaitPoint(i);
                }
                GUILayout.EndHorizontal();

                EditorGUILayout.BeginVertical();

                for (int j = 0; j < _trafficLight.waitPointMaps[i].NpcWaitPoints.Count; j++)
                {
                    
                    GUILayout.BeginHorizontal();
                    GUILayout.Label("   -->",GUILayout.Width(40));
                    EditorGUILayout.ObjectField(_trafficLight.waitPointMaps[i].NpcWaitPoints[j], typeof(GameObject),GUILayout.Width(160));
                    if (GUILayout.Button("删除"))
                    {
                        _trafficLight.DeleteWaitPoint(i, j);
                    }
                    GUILayout.EndHorizontal();
                    
                }

                EditorGUILayout.EndVertical();
                
                EditorGUILayout.Space(10);
            }
        }
    }
}
